package com.woniuxy.ssh.action.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.interceptor.SessionAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.woniuxy.ssh.action.BaseAction;
import com.woniuxy.ssh.entity.WaterAndElecInfo;
import com.woniuxy.ssh.service.WaterElecDataEnterService;


@Controller
@Scope("prototype")
public class WaterElecDataEnterAction extends BaseAction<WaterAndElecInfo> implements SessionAware{
	private static final long serialVersionUID = 1L;
	
	@Resource(name="waterElecDataEnterService")
	private WaterElecDataEnterService enterService;
	private Map<String,Object> session;
	private List<WaterAndElecInfo> wae;
	
	public String list(){
		
		this.wae = enterService.findAll();
		return SUCCESS;
	}

	public String toAdd(){
		String hql1 = "from WaterAndElecInfo where room_id=?";
		String hql2 = "update WaterAndElecInfo set last_water_info=this_water_info,last_electricity_info=this_electricity_info,"
				+ "last_record_date=this_record_date where room_id=?";

		String roomId = this.model.getRoom_id();
		
		this.enterService.executeUpdateByHQL(hql2,roomId);
		this.wae = this.enterService.findEntityByHQL(hql1, roomId);
		return "toAdd";
	}

	public String updateWaterAndElecData(){
		String hql = "update WaterAndElecInfo set this_water_info=?,this_electricity_info=?,this_record_date=? where room_id=?";
		
		this.enterService.executeUpdateByHQL(hql, model.getThis_water_info(),model.getThis_electricity_info(),model.getNewTime(),model.getRoom_id());
		
		return "toRoomInfo";
	}
	
	

	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}
	public List<WaterAndElecInfo> getWae() {
		return wae;
	}


}
